#ifndef __LUA_CONWIN_H_CHECK__
#define __LUA_CONWIN_H_CHECK__

#include "lua-sub-states.h"

#include "windows.h"

#define IS_FREED_BUFF_BOUNDED(i, buffer)\
	((intptr_t)((buffer)[i]) >= 0 && (intptr_t)((buffer)[i]) <= MAX_FREED_INDEX)

#define IS_FREED_BUFF(i, buffer)\
	((i) < 0 || (i) >= (int)((buffer).size()) || IS_FREED_BUFF_BOUNDED(i, buffer))

extern std::vector <int32_t*> semigraphics_bufs;
extern int gfx_index, tmp_gfx_index, tmp_gfx_index_2;
extern int luaevent_altkey_flags, tmp_input_pos_0;
extern int luacon_altmenu_suspend_count;
extern char* SDL_curr_status;
extern int32_t* luacon_mask_table_0;

extern bool fullscreened, fullscreen_wait, enable_fullscreen_shortcut;

extern CRITICAL_SECTION luacon_critical_0, luacon_critlib_lock_0;

void recreate_window_menu (bool init);

void drawchr_inv (int32_t* buf, int x, int y, int c);

int console_alloc_scrn (int i);
bool console_free_scrn (int i);
// void SwitchToMainThread (void* h);
// void luacon_wait_thread_0 ();

bool console_event_process(int sdl_key, uint16_t unicode, uint16_t mod, int32_t * textbuf, bool entered, int * _quit, char * cmd);
void SDL_console_key_release(int sdl_key, uint16_t mod);
void console_altmode_call(bool altflag, char * cmd);

int luacon_alt_loadf (lua_State * L);
int luacon_alt_loadst (lua_State * L);
int luaevent_cleanup_handles (lua_State * L);

void luacon_initCriticals ();

#ifndef __EVENT_CPP__
#include "lua-altsuspend.h"

int luaL_optint_gfx_i (lua_State * L, int n);

int luacon_alloc_scrn (lua_State*);
int luacon_free_scrn (lua_State*);
int luacon_window_cnt (lua_State*);
int luacon_window_cpct (lua_State*);
int luacon_window_recalc (lua_State*);
int luacon_switch_window (lua_State*);
int luacon_check_window (lua_State*);
int luacon_next_window (lua_State*);
int luacon_set_fullscreen (lua_State*);

int luacon_window_fileop (lua_State*);

int SDL_add_status_bar (int32_t *buf);
void console_blue_screen (lua_State*,int32_t*);

int luacon_popmessage (lua_State*);

#endif
#endif